package com.ruoyi.drill.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.firefighter.domain.FirefighterInfo;
import com.ruoyi.firefighter.service.IFirefighterInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.drill.mapper.FirefighterDrillMapper;
import com.ruoyi.drill.domain.FirefighterDrill;
import com.ruoyi.drill.service.IFirefighterDrillService;

/**
 * 重大演习演练Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Service
public class FirefighterDrillServiceImpl implements IFirefighterDrillService
{
    @Autowired
    private FirefighterDrillMapper firefighterDrillMapper;
    @Autowired
    private IFirefighterInfoService iFirefighterInfoService;

    /**
     * 查询重大演习演练
     *
     * @param id 重大演习演练主键
     * @return 重大演习演练
     */
    @Override
    public FirefighterDrill selectFirefighterDrillById(Long id)
    {
        return firefighterDrillMapper.selectFirefighterDrillById(id);
    }

    /**
     * 查询重大演习演练列表
     *
     * @param firefighterDrill 重大演习演练
     * @return 重大演习演练
     */
    @Override
    public List<FirefighterDrill> selectFirefighterDrillList(FirefighterDrill firefighterDrill)
    {
        return firefighterDrillMapper.selectFirefighterDrillList(firefighterDrill);
    }

    /**
     * 新增重大演习演练
     *
     * @param firefighterDrill 重大演习演练
     * @return 结果
     */
    @Override
    public int insertFirefighterDrill(FirefighterDrill firefighterDrill)
    {
        FirefighterInfo firefighterInfo1 = new FirefighterInfo();
        firefighterInfo1.setIdCardNumber(firefighterDrill.getFirefighterIdCard());
        FirefighterInfo firefighterInfo= iFirefighterInfoService.selectFirefighterInfoBySfz(firefighterInfo1);
        if (firefighterInfo==null){
            return 0;
        }
        firefighterDrill.setFirefighterId(firefighterInfo.getUserId());
        firefighterDrill.setCreateTime(DateUtils.getNowDate());
        return firefighterDrillMapper.insertFirefighterDrill(firefighterDrill);
    }

    /**
     * 修改重大演习演练
     *
     * @param firefighterDrill 重大演习演练
     * @return 结果
     */
    @Override
    public int updateFirefighterDrill(FirefighterDrill firefighterDrill)
    {
        firefighterDrill.setUpdateTime(DateUtils.getNowDate());
        return firefighterDrillMapper.updateFirefighterDrill(firefighterDrill);
    }

    /**
     * 批量删除重大演习演练
     *
     * @param ids 需要删除的重大演习演练主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterDrillByIds(Long[] ids)
    {
        return firefighterDrillMapper.deleteFirefighterDrillByIds(ids);
    }

    /**
     * 删除重大演习演练信息
     *
     * @param id 重大演习演练主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterDrillById(Long id)
    {
        return firefighterDrillMapper.deleteFirefighterDrillById(id);
    }

    @Override
    public void deleteFirefighterDrillById1(Long userId) {
         firefighterDrillMapper.deleteFirefighterDrillByIds1(userId);
    }
}
